package rs.edu.fit.setupdata;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

import rs.edu.fit.model.ExamSchedule;
import rs.edu.fit.setupdata.actions.GenerateExams;
import rs.edu.fit.setupdata.actions.GenerateStudents;


public class SplitExams {
	private FillExams fillExams;
	
	private Collection<ExamSchedule> lFirstYearExamSchedule;
	private Collection<ExamSchedule> lSecondYearExamSchedule;
	private Collection<ExamSchedule> lThridYearExamSchedule;
	
	private Logger log = Logger.getLogger("rs.edu.fit.setupdata.SplitExams");
	
	public SplitExams() {
		fillExams = new FillExams(GenerateStudents.createList(250), GenerateExams.createList());
		lFirstYearExamSchedule = new ArrayList<ExamSchedule>();
		lSecondYearExamSchedule = new ArrayList<ExamSchedule>();
		lThridYearExamSchedule = new ArrayList<ExamSchedule>();
		
		BasicConfigurator.configure();
	}
	
	public final void execute() {
		fillExams.execute();
		for (ExamSchedule examSchedule : fillExams.getlExamsSchedule()) {
			if (isFirstYearExam(examSchedule)) {
				lFirstYearExamSchedule.add(examSchedule);
				continue;
			} else if (isSecondYearExam(examSchedule)) {
				lSecondYearExamSchedule.add(examSchedule);
				continue;
			} else if (isThirdYearExam(examSchedule)) {
				lThridYearExamSchedule.add(examSchedule);
				continue;
			} else {
				log.warn("Exam is out of place.");
			}
		}
	}
	
	private final boolean isFirstYearExam(ExamSchedule examSchedule) {
		return examSchedule.getExam().getYearOfStudy() == 1;
	}
	
	private final boolean isSecondYearExam(ExamSchedule examSchedule) {
		return examSchedule.getExam().getYearOfStudy() == 2;
	}
	
	private final boolean isThirdYearExam(ExamSchedule examSchedule) {
		return examSchedule.getExam().getYearOfStudy() == 3;
	}
	
	/* Only getters and setters, no login here. */

	/**
	 * @return the fillExams
	 */
	public final FillExams getFillExams() {
		return fillExams;
	}

	/**
	 * @return the lFirstYearExamSchedule
	 */
	public final Collection<ExamSchedule> getlFirstYearExamSchedule() {
		return lFirstYearExamSchedule;
	}

	/**
	 * @return the lSecondYearExamSchedule
	 */
	public final Collection<ExamSchedule> getlSecondYearExamSchedule() {
		return lSecondYearExamSchedule;
	}

	/**
	 * @return the lThridYearExamSchedule
	 */
	public final Collection<ExamSchedule> getlThridYearExamSchedule() {
		return lThridYearExamSchedule;
	}
	
	
}
